﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using DrugStorehouseMIS.BLL;


namespace DrugStorehouseMIS
{
    public partial class frmLogin : Form
    {
        AutoCompleteStringCollection acsc = new AutoCompleteStringCollection();
        private User userBLL = new User();

        public frmLogin()
        {
            InitializeComponent();
        }

        private void login_Load(object sender, EventArgs e)
        {
            //List<string> list = new List<string>();
            //txtLogin.AutoCompleteMode = AutoCompleteMode.Suggest;
            //txtLogin.AutoCompleteSource = AutoCompleteSource.CustomSource;
            //txtLogin.AutoCompleteCustomSource = acsc;
            //AutoCompleteSource.ListItems = list;

            skinEngine1.SkinFile = AppDomain.CurrentDomain.BaseDirectory + @"\Skins\DiamondBlue.ssk";
            pbxLogin.ImageLocation = AppDomain.CurrentDomain.BaseDirectory + @"\Images\icon_login.png";
            this.txtLogin.Focus();

            
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            int temp;

            if (txtLogin.Text.Trim() == "")
                MessageBox.Show(" 请输入用户名", "提示 ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            else if (txtPwd.Text.Trim() == "")
                MessageBox.Show(" 请输入密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            else
            {
                temp = userBLL.Login(txtLogin.Text.Trim(), txtPwd.Text.Trim());
               
                if (temp == 1)
                {                    
                    this.Visible = false;
                    User obj = new User();
                    obj = userBLL.GetUser(txtLogin.Text.Trim());
                    frmMain main = new frmMain(obj);
                    main.Show();
                }
                else if (temp == 0)
                    MessageBox.Show("当前用户不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else if (temp == -1)
                    MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }       

        private void btnReset_Click(object sender, EventArgs e)
        {
            txtLogin.Text = txtPwd.Text = string.Empty;
        }


        /// <summary>
        /// 标题动态效果
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.Visible == true)
                labelHeader.Text = labelHeader.Text.Substring(1) + labelHeader.Text.Substring(0, 1);
            else
                this.timer1.Stop();
        }

        /// <summary>
        /// 按Enter键跳到密码输入框
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtLogin_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                this.txtPwd.Focus();
        }

        /// <summary>
        /// 按Enter键登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtPwd_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                this.btnLogin_Click(sender, e);
        }

        private void txtLogin_TextChanged(object sender, EventArgs e)
        {
            acsc.Clear();
            acsc.Add("c#");
            acsc.Add("c++");
            acsc.Add("c#");
            acsc.Add("c++");
            acsc.Add("ddddddddddddd");
            acsc.Add("dcccccc");
        }
    }
}